package com.lry;

import gnu.io.CommPortIdentifier;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * @author JiangJie
 * @create 2020-11-27 15:17
 */
public class port {
    public static List<String> findComPort() {
        Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
        List<String> portNameList = new ArrayList<>();
        while (portList.hasMoreElements()) {
            String portName = portList.nextElement().getName();//名称如 COM1、COM2....
            portNameList.add(portName);
        }
        return portNameList;
    }

    public static void main(String[] args) {
        try {
            t();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    private static void t(){
        throw new RuntimeException("dfasf");
    }
}
